/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entities.ListeLecture;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Nordinator
 */
@Stateless
@LocalBean
public class ListeLectureManager {
    @PersistenceContext(unitName = "Project-MP3-Rumble-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    public List<ListeLectureManager> getAllListeLectureManager() {
        Query query = em.createNamedQuery("ListeLecture.findAll");
        return query.getResultList();
    }
    
    /**
     * Effacer une liste de lecture
     */
    public void rmListeLecture(ListeLecture listeLecture){
        em.remove(listeLecture);
    }
    
    /**
     * Ajouter une liste de lecture à la base
     * @param listeLecture 
     */
    public void addListeLecture(ListeLecture listeLecture){
        em.persist(listeLecture);
    }
    
    /**
     * Methode pour crée je ne sais quoi mais je trouverai HéHéHé !!!
     * @return
     */
    public ListeLecture getAListeDeLecture(Long id){
        ListeLecture res = null;
        try{
            Query query = em.createNamedQuery("ListeLecture.findById");
            query.setParameter("id", id);
            res = (ListeLecture) query.getResultList().get(0);
        }catch(ArrayIndexOutOfBoundsException e){
            System.out.println("ListeLectureManager.getAListDeLActure() : Aucune élément n'as été récuperer !");
        }catch(Exception e){
            
        }
        return res;
    }
    
    /**
     * 
     * @param liste
     * @return 
     */
    public ListeLecture update(ListeLecture liste) {
        return em.merge(liste);
    }
    
    public void Test(){
        
    }
}
